package com.kingdee.pda.ui.scan_inwarehouse;

import android.content.Context;

import com.example.basecommon.http.MyObserver;
import com.example.basecommon.http.RxHelper;
import com.example.basecommon.http.rxjava.BaseResponse;
import com.example.basecommon.http.rxjava.HttpUtils;
import com.example.basecommon.utils.ConstantUtil;
import com.kingdee.pda.Api;
import com.kingdee.pda.entity.ScanSnResponsebean;

import java.util.HashMap;
import java.util.List;

/**
 * @author：dlj
 * @data：2021/11/15:16:31
 * @des：扫描收货Presenter
 */
public class ScanReceivePresenter implements ScanReceiveContract.IScanReceivePresenter {
    private Context context;
    private ScanReceiveContract.IScanReceiveView view;

    public ScanReceivePresenter(Context context, ScanReceiveContract.IScanReceiveView view) {
        this.context = context;
        this.view = view;
    }


    @Override
    public void pdaSnScan(String sn) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("SN", sn);
        map.put("snStatus", "wh_out");

        MyObserver<ScanSnResponsebean> myObserver = new MyObserver<ScanSnResponsebean>(context) {
            @Override
            public void onSuccess(BaseResponse<ScanSnResponsebean> result) {
                view.pdaSnScanSuccess(result.data);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                view.pdaSnScanFailed(result.message);
            }
        };
        HttpUtils.request(Api.class)
                .pdaScanSn(ConstantUtil.PDASNSCAN, map)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }

    @Override
    public void pdaCollectNullSn(String sn) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("SN", sn);
        map.put("snStatus", "in_library");

        MyObserver<ScanSnResponsebean> myObserver = new MyObserver<ScanSnResponsebean>(context, false) {
            @Override
            public void onSuccess(BaseResponse<ScanSnResponsebean> result) {
                view.pdaCollectNullSnSuccess(result.data);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                view.pdaCollectNullSnFailed(result.message);
            }
        };
        HttpUtils.request(Api.class)
            .pdaScanSn(ConstantUtil.PDACOLLECTNULLSN, map)
            .compose(RxHelper.observableIO2Main(context))
            .subscribe(myObserver);
    }

    @Override
    public void confirmReceipt(List<ScanReceiveOrderBean.AsnListBean> asnListBeanList) {
        ScanReceiveRequestBean scanReceiveRequestBean = new ScanReceiveRequestBean();
        scanReceiveRequestBean.setConfirmReceiptVo(asnListBeanList);
        MyObserver myObserver = new MyObserver(context) {
            @Override
            public void onSuccess(BaseResponse result) {
                view.confirmReceiptResult(true, result.message);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                view.confirmReceiptResult(false, result.message);
            }
        };
        HttpUtils.request(Api.class)
                .confirmReceipt(ConstantUtil.CONFIRMRECEIPT, scanReceiveRequestBean)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }
}
